﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.XZModel
{
    public partial class XZKaoQinAdd : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }
        protected override string DWZRef
        {
            get { return "XZKaoQinList"; }
        }

        protected int KQType
        {
            get
            {
                return GetRequestValue<int>("KQType",1);
            }
        }

        protected string GetKQTypeStr()
        { 
            string r="";
            switch(KQType)
            {
                case 1:
                    r="加班";
                    break;
                case 2:
                    r="迟到";
                    break;
                case 3:
                    r="早退";
                    break;
                case 4:
                    r="请假";
                    break;
                case 5:
                    r = "漏打卡";
                    break;

            }
            return r;
        }

        #region

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
            }
        }

        protected void addmenu()
        {
            XZKaoQinInfo obj2 = Request.SerializableObject<XZKaoQinInfo>();
            obj2.KQType = GetKQTypeStr();
            //批量添加处理
            char[] caSplit = new char[] { ',' };
            string[] userNames = GetRequestValue<string>("UserName", "").Split(caSplit); ;
            string[] realNames = GetRequestValue<string>("RealName", "").Split(caSplit); ;
            List<XZKaoQinInfo> kqObjs = new List<XZKaoQinInfo>();
            for (int rowIndex = 0; rowIndex < userNames.Count(); rowIndex++)
            {
                if (userNames[rowIndex].Trim() != "")
                {
                    XZKaoQinInfo tempObj = new XZKaoQinInfo();
                    tempObj.KQType = obj2.KQType;
                    tempObj.KQDate = obj2.KQDate;
                    tempObj.KQState = obj2.KQState;
                    tempObj.KQValue = obj2.KQValue;
                    tempObj.Remark = obj2.Remark;

                    tempObj.GongHao = userNames[rowIndex];
                    tempObj.RealName = realNames[rowIndex];

                    kqObjs.Add(tempObj);
                }

            }


            //obj2.GongHao = GetRequestValue<string>("dwz.RealName.UserName","");
            //obj2.RealName = GetRequestValue<string>("dwz.orgLookup.RealName", "");
            //  obj2.AddRealName = User.RealName;

            this.AddLog(Permission.新增, "", obj2);
            if (XZKaoQinController.Add(kqObjs) > 0)
            {
                if (IsRefreshPar)
                {
                    SuccessJson("添加成功");
                }
                else
                {
                    SuccessAlertJson("添加成功");
                }
            }
            else
                ErrorJson("添加失败");
        }
    }
}